package com.tmall.tmall.mapper;

import com.tmall.tmall.pojo.Orderitem;
import com.tmall.tmall.pojo.ProductRt;
import com.tmall.tmall.pojo.Products;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderitemMapper {

    void insertBatch(List<Products> productList);

    @Update("update orderitem set delete_at = #{now} where oid=#{oid} and delete_at is null")
    void deleteByOid(Integer oid, LocalDateTime now);

    @Select("select pid as id,number,sum,status as item_status from orderitem where delete_at is null and oid=#{oid}")
    List<ProductRt> selectByOid(Integer oid);

    @Select("select * from orderitem where delete_at is null and oid=#{oid}")
    List<Orderitem> getByOid(Integer oid);

    void update(Orderitem orderitem);

    @Update("update orderitem set deliver_date=#{now},status=#{i} where oid=#{oid} and pid=#{pid}")
    void deliver(Integer oid, Integer pid, int i, LocalDateTime now);

    @Update("update orderitem set confirm_date=#{now},status=#{i} where oid=#{oid} and pid=#{pid}")
    void confirm(Integer oid, Integer pid, int i, LocalDateTime now);

    @Update("update orderitem set status=#{i} where oid=#{oid}")
    void uStatus(Integer oid, int i);

    @Update("update orderitem set status=#{i} where pid=#{productId} and oid=#{productOrderId}")
    void ok(Integer productOrderId, Integer productId, int i);
}
